package leetcode_bin_tree_test;

import bin_tree.TreeNode;

/**
 * 剑指 Offer II 052. 展平二叉搜索树
 */
public class IncreasingBST {
    TreeNode backNode;
    // 自下而上的递归
    // 方法仅仅起到遍历的作用
    public TreeNode increasingBST(TreeNode root) {
        if (root == null) {
            return null;
        }
        increasingBST(root.right);

        // 起到记录路径，并且连接的作用
        root.right = backNode;
        backNode = root;

        increasingBST(root.left);
        root.left = null;
        return backNode;
    }
}
